package handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import packet.impl.MessageRequestAbstractPacket;
import packet.impl.MessageResponseAbstractPacket;

import java.util.Date;

/**
 * @author Admin
 */
public class MessageRequestHandler extends SimpleChannelInboundHandler<MessageRequestAbstractPacket> {

  @Override
  protected void channelRead0(ChannelHandlerContext ctx, MessageRequestAbstractPacket messageRequestPacket) {
    System.out.println(new Date() + ": 收到客户端消息【" + messageRequestPacket.getMessage() + "】");

    MessageResponseAbstractPacket messageResponsePacket = new MessageResponseAbstractPacket();
    messageResponsePacket.setMessage("服务端回复【" + messageRequestPacket.getMessage() + "】");

    ctx.channel().writeAndFlush(messageResponsePacket);
  }
}
